#ifndef _PICTURE_H_
#define _PICTURE_H_

#include <thread>
#include <mutex>
#include <map>
#include "PictureUI.h"

class Picture
{
public:
private:
    std::thread *pthread; // 数据处理线程
    bool threadExitFlag;  // 指定线程退出标记
    std::mutex *uiMutex;

    std::map<int, std::string> imageTable; // 图像映射表
    std::mutex updateMutex;

    int destpage = 1; // 目标页面


    int threadFunction(void);
    int searchImage(std::string &path, int listMax);
    void updateImageListPage(int page);
    void getImage(int tag, PictureUI::ImgInfo *info);
    int getNextTag(int curTag);
    int getPrevTag(int curTag);
    void changeImageListPage(int page);

public:
    Picture(std::function<void(void)> exitCb, std::mutex &uiMutex);
    ~Picture();

    static unsigned char *bmpImageDecode(std::string &file, int &wight, int &height, int &bitPerPixel);
    static unsigned char *jpegImageDecode(std::string &file, int &wight, int &height, int &bitPerPixel);
    static unsigned char *pngImageDecode(std::string &file, int &wight, int &height, int &bitPerPixel);
};

#endif
